/*
*PopBell Application for Android
*Copyright (C) 2013 SimpleMinds Team
*
*This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License
*as published by the Free Software Foundation; either version 2
*of the License, or (at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program; if not, write to the Free Software
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package com.simpleminds.popbell;
import wei.mark.standout.StandOutWindow;
import wei.mark.standout.constants.StandOutFlags;
import wei.mark.standout.ui.Window;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.Vibrator;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
public class TouchTrigger extends StandOutWindow {
private ImageView mTouchDetector;
@Override
public String getAppName() {
return null;
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int getAppIcon() {
return android.R.drawable.ic_menu_close_clear_cancel;
}
@Override
public void createAndAttachView(int id, FrameLayout frame) {
boolean Useleft = getSharedPreferences("pref", Context.MODE_PRIVATE).getBoolean("useleft", true);
// create a new layout from body.xml
mTouchDetector = new ImageView(this);
if(Useleft){
mTouchDetector.setImageResource(R.drawable.detector_left);
}else{
mTouchDetector.setImageResource(R.drawable.detector_right);
}
frame.addView(mTouchDetector);
mTouchDetector.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibe.vibrate(10);
Intent intent = new Intent(TouchTrigger.this, DrawerActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(intent);
}
return true;
}
});
}
// the window will be centered
@Override
public StandOutLayoutParams getParams(int id, Window window) {
boolean Useleft = getSharedPreferences("pref", Context.MODE_PRIVATE).getBoolean("useleft", true);
String Triggerpos = getSharedPreferences("pref", Context.MODE_PRIVATE).getString("touchtrigger_align", "");
int triggerpos = StandOutLayoutParams.CENTER;
if(Triggerpos.equals("top")){
triggerpos = StandOutLayoutParams.TOP;
}
else if(Triggerpos.equals("middle")){
triggerpos = StandOutLayoutParams.CENTER;
}
else{
triggerpos = StandOutLayoutParams.BOTTOM;
}
if(Useleft){
return new StandOutLayoutParams(id, StandOutLayoutParams.WRAP_CONTENT, StandOutLayoutParams.WRAP_CONTENT, StandOutLayoutParams.LEFT, triggerpos);
}else{
return new StandOutLayoutParams(id, StandOutLayoutParams.WRAP_CONTENT, StandOutLayoutParams.WRAP_CONTENT, StandOutLayoutParams.RIGHT, triggerpos);
}
}
// move the window by dragging the view
@Override
public int getFlags(int id) {
return super.getFlags(id) | StandOutFlags.FLAG_WINDOW_FOCUSABLE_DISABLE;
}
}